<div class="bjui-pageContent">
    <form id="modify-password" method="post" class="form-horizontal" action="/account/changePassword">
        <div class="form-group">
            <label class="col-lg-12 col-sm-12 control-label"><span class="required-span">*</span>旧密码:
                
            </label>
            <div class="col-lg-12 col-sm-12">
                <div class="input-group">
                    <span class="input-group-addon">
                        <i class="fa fa-lock" aria-hidden="true"></i>
                    </span>
                    <input type="password" class="form-control input-nm" name="oldPassword" >
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-12 col-sm-12 control-label"><span class="required-span">*</span>新密码:
                
            </label>
            <div class="col-lg-12 col-sm-12">
                <div class="input-group">
                    <span class="input-group-addon">
                        <i class="fa fa-lock" aria-hidden="true"></i>
                    </span>
                    <input type="password" class="form-control input-nm" name="newPassword" >
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-12 col-sm-12 control-label"><span class="required-span">*</span>确认密码:
                
            </label>
            <div class="col-lg-12 col-sm-12">
                <div class="input-group">
                    <span class="input-group-addon">
                        <i class="fa fa-lock" aria-hidden="true"></i>
                    </span>
                    <input type="password" class="form-control input-nm" name="newPassword2" >
                </div>
            </div>
        </div>
    </form>
</div>
<div class="btns-group bjui-pageFooter">
    <button type="button" class="close-btn">取消</button>
    <button type="submit" class="save-btn">保存</button>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        dialog_close();
        $('#modify-password')
        .formValidation({
            icon: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            trigger:'blur',
            fields: {
                oldPassword: {
                    validators: {
                      notEmpty: {
                          message: '请填写旧密码'
                        }
                      }
                },
                newPassword: {
                    validators: {
                      notEmpty: {
                          message: '请填写新密码'
                        },
                        regexp: {
                            regexp: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9a-zA-Z]{8,}/,
                            message: '不能纯数字或纯字母,长度至少为8位'
                        }
                    }
                },
                newPassword2: {
                    validators: {
                        notEmpty: {
                        message: '请填写确认密码'
                        },
                        identical: {
                        field: 'newPassword',
                        message: '密码与确认密码不一致'
                        },
                        regexp: {
                            regexp: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9a-zA-Z]{8,}/,
                            message: '不能纯数字或纯字母,长度至少为8位'
                        }
                    }
                }
            }
        })
        .on('success.form.fv', function(e) {
            // Prevent form submission
            e.preventDefault();
            var fromArr=[];
            var $form = $(e.target);
            var fromDateArr=$form.serialize().split('&');
            $.each(fromDateArr,function(i,item){
                fromArr.push(item.split('=')[1]);
            })
            // Get the form instance
            // Get the FormValidation instance
            var bv = $form.data('formValidation');
            // Use Ajax to submit form data
            $.post($form.attr('action'),{'oldPassword':strEnc(fromArr[0],1,2,3),'newPassword':strEnc(fromArr[1],1,2,3),'newPassword2':strEnc(fromArr[2],1,2,3)}, function(result) {
                if(result.statusCode=='200'){
                    BJUI.alertmsg('ok','修改成功,即将自动返回登录页面');
                    BJUI.dialog('closeCurrent');
                    setTimeout("location.href = '/login'",3000);
                    // location.href = "/login";
                }else{
                  BJUI.alertmsg('error',result.message);
                }
            }, 'json');
        });
        });
</script>